Skip to content

Reject static item as direct const generic arg#158479

Open
Shourya742 wants to merge 2 commits into
rust-lang:mainfrom
Shourya742:2026-06-27-emit-error-during-ast-lower-using-static-const
Open

Reject static item as direct const generic arg#158479
Shourya742 wants to merge 2 commits into
rust-lang:mainfrom
Shourya742:2026-06-27-emit-error-during-ast-lower-using-static-const

Conversation

@Shourya742

@Shourya742 Shourya742 commented Jun 27, 2026

Copy link
Copy Markdown
Member

closes: #136139

This PR fixes the ICE and not add support for static in MGCA

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 27, 2026
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 17 candidates

@Shourya742

Copy link
Copy Markdown
Member Author

r? @BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned JohnTitor Jun 27, 2026
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms Bot force-pushed the 2026-06-27-emit-error-during-ast-lower-using-static-const branch from 67f73a3 to c5de45f Compare June 27, 2026 14:27
@BoxyUwU

BoxyUwU commented Jul 8, 2026

Copy link
Copy Markdown
Member

sry for taking so long to get to this, thanks for looking into this ICE ✨

This probably merge conflicts with #158617, but more usefully it'd theoretically also let us fallback to an anon const instead of erroring if we wish 🤔 though i think for now i'd like to hold off on making the can_lower_to_direct_const_arg too clever (i.e. using name res information) which means that continuing to error feels right.

i think I would prefer for us to not handle special case statics during ast lowering in any way, and instead error during HIR ty lowering when encountering a static 🤔 im not sure I understand why I feel this way 😅 we do already have some semantic checks in HIR ty lowering about what kind of thing we resolved to (e.g. type const or non type const) so I think it just feels like we do our semantic checks there and syntactic checks in ast lowering.

can you emit these errors in HIR ty lowering instead :3

let msg = "complex const arguments must be placed inside of a `const` block";
hir::ConstArgKind::Error(self.dcx().struct_span_err(span, msg).emit())
} else if is_trivial_path || tcx.features().min_generic_const_args() {
let qpath = self.lower_qpath(

@BoxyUwU BoxyUwU Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @khyperia i don't think we handled this codepath in your PR overhauling ast lowering for mgca. we should probably be checking can_lower_to_direct_const_arg here and then also reusing the lower_expr_to_direct logic here? though it would really just be the path arms right now but still... seems nice for consistency/sharing logic 🤔

unrelated to this PR, just something i realised while reading this

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yus, the logic here happens to be identical even with the syntax flip PR, but, it's a very wishy-washy "happens to be correct" and you're absolutely right that these should share a codepath so they don't accidentally diverge

@BoxyUwU

BoxyUwU commented Jul 8, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rustc crashes at compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2156:17

6 participants